package com.watson.patterns.behavior.observer;

import java.util.ArrayList;
import java.util.List;

public class WechatObserverable implements Observerable {

    List<Observer> observers = new ArrayList<>();

    public String message;

    @Override
    public void registerObserver(Observer object) {
        observers.add(object);
    }

    @Override
    public void deleteObserver(Observer object) {
        observers.remove(object);
    }

    @Override
    public void notifyAllObserver() {
        observers.forEach(observer -> {
            observer.update(message);
        });
    }

    public void setMessage(String message) {
        this.message = message;
        notifyAllObserver();
    }
}
